<?php

if (!defined('NV_SYSTEM')) { die ("You can't access this file directly..."); }

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
if (file_exists("".$datafold."/config_".$module_name.".php")) {
	@require_once ("".$datafold."/config_".$module_name.".php");
}
if (defined('_MODTITLE')) $module_title = _MODTITLE;
##########################################

$index = 0;

/*Khai bao*/
$url_get_content = 'http://www.vietcombank.com.vn/ExchangeRates/';//Link den trang thong tin ngoai te
$sourcename = "VietComBank";//Ten nguon
$pattern = '#<tr[^>]*>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<td[^>]*>[\s\r\n\t]*<font[^>]+>[\s\r\n\t]*([^<]+)[\s\r\n\t]*<br>[\s\r\n\t]*<\/font>[\s\r\n\t]*<\/td>[\s\r\n\t]*<\/tr>#si';//Cach loc thong tin
/*Het phan khai bao*/
	
$cache_file = INCLUDE_PATH . $datafold . '/exchangerates_' . md5($url_get_content).'.cache';
$read_file = false;
if(file_exists($cache_file) AND filesize($cache_file)!=0) {
	$timedif = @(time() - filemtime($cache_file));
	if ($timedif < 86400) {
		$read_file = true;
	}
}
clearstatcache();
$unserialize = array();
if($read_file) {
	$unserialize = unserialize(file_get_contents($cache_file));
} else {
	$method = detect_openfile_methods();
	if(in_array('file_get_contents',$method)) {
		$method = 'file_get_contents';
	} else {
		$method = $method[0];
	}
	if($method!="") {
		$urlcontent = get_contents($url_get_content,$method);
		if($urlcontent!="") {
			preg_match_all($pattern,$urlcontent,$uns);
			unset($uns[0]);
			$unserialize['contents'] = array_values($uns);
			$unserialize['url'] = $url_get_content;
			$unserialize['urlname'] = $sourcename;
			$unserialize['updatetime'] = time();
			@$file = fopen($cache_file, "w");
			$serialized = serialize($unserialize);
			@fwrite($file, $serialized);
			@fclose($file);
		}
	}
}

include("header.php");
if($unserialize!=array()) {
	//OpenTable();
	$codes = $unserialize['contents'][0];
	$names = $unserialize['contents'][1];
	$buyings = $unserialize['contents'][2];
	$transfers = $unserialize['contents'][3];
	$sellings = $unserialize['contents'][4];
	echo "<div style=\"font-family: Arial; font-size: 12px; \">"._VALUESUPDATE.": ".viewtime($unserialize['updatetime'], 2)."</div>\n";
	echo "<div style=\"font-family: Arial; font-size: 12px; \">"._BANKNAME.": <a target=\"_blank\" href=\"".$unserialize['url']."\">".$unserialize['urlname']."</a></div><br>\n";
	echo "<table border=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellspacing=\"0\">\n";
	echo "<tr>\n";
	echo "<td height=\"20\" style=\"text-align: center; font-family: Tahoma; font-size: 12px; color: #0055A5; font-weight: bold; border: 1px solid #CCCCCC\"><div style=\"padding:2px;margin:2px\">\n";
	echo _CURRENCYCODE."</div></td>\n";
	echo "<td height=\"20\" style=\"text-align: center; font-family: Tahoma; font-size: 12px; color: #0055A5; font-weight: bold; border: 1px solid #CCCCCC\"><div style=\"padding:2px;margin:2px\">\n";
	echo _CURRENCYNAME."</div></td>\n";
	echo "<td height=\"20\" style=\"text-align: center; font-family: Tahoma; font-size: 12px; color: #0055A5; font-weight: bold; border: 1px solid #CCCCCC\"><div style=\"padding:2px;margin:2px\">\n";
	echo _BUYING."</div></td>\n";
	echo "<td height=\"20\" style=\"text-align: center; font-family: Tahoma; font-size: 12px; color: #0055A5; font-weight: bold; border: 1px solid #CCCCCC\"><div style=\"padding:2px;margin:2px\">\n";
	echo _TRANSFER."</div></td>\n";
	echo "<td height=\"20\" style=\"text-align: center; font-family: Tahoma; font-size: 12px; color: #0055A5; font-weight: bold; border: 1px solid #CCCCCC\"><div style=\"padding:2px;margin:2px\">\n";
	echo _SELLING."</div></td>\n";
	echo "</tr>\n";
	foreach($codes as $key => $code) {
		$cl = ($key%2==0) ? '#EFEFEF' : '#FFFFFF';
		echo "<tr>\n";
		echo "<td bgcolor=\"$cl\" height=\"20\" style=\"border: 1px solid #CCCCCC;font-family:Tahoma; font-size: 12px;\" nowrap=\"nowrap\"><div style=\"padding:2px;margin:2px\">".$code."</div></td>\n";
		echo "<td bgcolor=\"$cl\" height=\"20\" style=\"border: 1px solid #CCCCCC;font-family:Tahoma; font-size: 12px;\" nowrap=\"nowrap\"><div style=\"padding:2px;margin:2px\">".ucwords(strtolower($names[$key]))."</div></td>\n";
		echo "<td bgcolor=\"$cl\" height=\"20\" style=\"border: 1px solid #CCCCCC;font-family:Tahoma; font-size: 12px;text-align:right\" nowrap=\"nowrap\"><div style=\"padding:2px;margin:2px\">".$buyings[$key]."</div></td>\n";
		echo "<td bgcolor=\"$cl\" height=\"20\" style=\"border: 1px solid #CCCCCC;font-family:Tahoma; font-size: 12px;text-align:right\" nowrap=\"nowrap\"><div style=\"padding:2px;margin:2px\">".$transfers[$key]."</div></td>\n";
		echo "<td bgcolor=\"$cl\" height=\"20\" style=\"border: 1px solid #CCCCCC;font-family:Tahoma; font-size: 12px;text-align:right\" nowrap=\"nowrap\"><div style=\"padding:2px;margin:2px\">".$sellings[$key]."</div></td>\n";
		echo "</tr>\n";
	}
	echo "</table>\n";
	echo "<br>\n";
	//CloseTable();
}
include("footer.php");

?>
